package com.hd.crdao.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 *
 *@author Programming
 *@date 2017/7/24 0024
 */

public class CheckNetworkUtils {

        /** 检查是否有网络 */
        public static boolean isNetworkAvailable() {
            NetworkInfo info = getNetworkInfo(UIUtils.getContext());
            return info != null && info.isAvailable();
        }

        /** 检查是否是WIFI */
        public static boolean isWifi() {
            NetworkInfo info = getNetworkInfo(UIUtils.getContext());
            return info != null && info.getType() == ConnectivityManager.TYPE_WIFI;
        }

        /** 检查是否是移动网络 */
        public static boolean isMobile() {
            NetworkInfo info = getNetworkInfo(UIUtils.getContext());
            if (info != null) {
                if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
                    return true;
                }
            }
            return false;
        }

        private static NetworkInfo getNetworkInfo(Context context) {

            ConnectivityManager cm = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            return cm.getActiveNetworkInfo();
        }
    }

